package com.android.goal;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class LeagueAdapter extends ArrayAdapter<League>{
	ArrayList<League> listLeague;	
	int resource;
	Context context;
	
	public LeagueAdapter(Context context, int textViewResourceId, 
			ArrayList<League> objects){		
		super(context, textViewResourceId, objects);
		this.context = context;
		this.resource = resource;
		this.listLeague = objects;
	}
	
	public View getView(int position, View convertView, ViewGroup parent){
		View leagueView = convertView;
		if(leagueView == null){
			leagueView = new LeagueViewGroup(getContext());
		}
		
		final League league = listLeague.get(position);
		if(league!=null){
			TextView competition = ((LeagueViewGroup) leagueView).competition;
			competition.setText(league.getCompetition());
			
			ListView listMatch = ((LeagueViewGroup) leagueView).listMatch;						
			MatchAdapter adapter= new MatchAdapter(context, 
					R.layout.match_view, league.getListMatch());											
			listMatch.setAdapter(adapter);
			listMatch.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					// TODO bat click vao 1 tran dau roi xu ly trong nay
					
				}
				
			});
			Utility.setListViewStatic(listMatch);
		}
		return leagueView;
	}
}
